/*
*DataLoader
*chenjie
*2012-5-5
*/
package com.loader
{
	import com.data.Data;
	import com.data.PlayModel;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	public class DataLoader extends EventDispatcher
	{
		private var loader:URLLoader
		public function DataLoader()
		{
			loader=new URLLoader()
			loader.addEventListener(Event.COMPLETE,doLoadComplete)
			loader.load(new URLRequest("flv.xml"))
		}
		
		public function doLoadComplete(e:Event):void{
//		  trace(loader.data)
		  var xml:XML=new XML(loader.data)
			var xmlList:XML= xml.child("item")[0]
//			 trace(xmlList.length())
//			 trace(xmlList["ad"].attributes())
//			 trace(xmlList["play"].attributes())
//			 trace(xmlList["play"].length())
			 
			 Data.adTime=int(xmlList["ad"].attributes())
//				trace( " sdsd "+Data.adTime) 
			 var allTime:int=0	
			 for(var i:int=0;i<xmlList["play"].length();i++){
				 var playModel:PlayModel=new PlayModel(xmlList["play"][i].attribute("url"),
					                                                                xmlList["play"][i].attribute("type"),
																					xmlList["play"][i].attribute("time"),
																					xmlList["play"][i].attribute("name"),
																					xmlList["play"][i].attribute("adUrl")
				 )
//				 Data.playArr.push(playModel)
				 Data.insertPlayModel(playModel,Data.XML)	
				 allTime +=int(playModel.time)
					 
			 }	 
			 
			 if(allTime < Data.adTime){
				 Data.adTime=allTime
			 }
//			 trace("Data.adTime "+Data.adTime)
			 dispatchEvent(new Event(Event.COMPLETE))
		}
		
	}
}